<?php
/**
 * Search page
 *  
 * @author Joseph Chereshnovsky <joseph.chereshnovsky@gmail.com>
 * @version 1.0
 */
$this->headTitle( $this->_('Search results') . ' "' . $this->search_phrase . '"' . ' :: ');

$this->headLink()->appendStylesheet(APP_URL . '/css/translation/search.css');
?>
<div id="search">

<form action="<?php echo APP_URL ?>/translation/search/" method="post">
	<div id="search-form-results">
		<script type="text/javascript">

			var enterRequestPhrase = "<?php echo $this->_('enter your phrase here...') ?>";

			function enableControl(textField)
			{
				if (textField.value == enterRequestPhrase) {
					textField.value = '';
					textField.className = '';
				}
			}

			function disableControl(textField)
			{
				if (textField.value == '') {
					textField.value = enterRequestPhrase;
					textField.className = 'disabled';
				}
			}

			window.onload = function () {
				disableControl(document.getElementById('search-field'));
			}

		</script>
	
		<input id="search-field" name="search-field" type="text" value="<?php echo $this->search_phrase ?>" onblur="disableControl(this)" onfocus="enableControl(this)"  />
		<input id="search-submit" type="submit" value="<?php echo $this->_('Search') ?>" />
	</div>
</form>

<h1><?php echo $this->_('Search results') ?></h1>

<div class="search-results-block">
<?php if (count($this->termsList) <= 0): ?>

	<div class="no-results"><?php echo $this->_('oups, no translation') ?></div>

<?php else: ?>

	<?php $i = 1; foreach($this->termsList as $key => $data): ?>
	<div <?php $i++; ?>class="term-item-row<?php echo $i%2 + 1 ?>">
		<?php /* ?>
		<div class="term-actions">
			<a href="#" onclick="alert('comming soon...')"><?php echo $this->_('see details') ?></a>
		</div>
		<?php */ ?>
		<div class="source-term">
			<?php 
			$text = $data['source_title'];
			
			$words = explode(' ', $this->search_phrase);
			foreach($words as $word) {
				$text = eregi_replace($word, "<span class='highlight'>\\0</span>", $text);
			}
			echo $text;
			?>
		</div>
		<div class="target-term">
			<?php echo $data['target_title'] ?>
		</div>
	</div>
	<?php endforeach; ?>

<?php endif; ?>
</div>

</div>